package com.example.crm.mapper.impl;

import com.example.crm.common.DBUtils;
import com.example.crm.mapper.UserMapper;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class UserMapperImpl implements UserMapper {
    @Override
    public boolean findByUsernamePassword(String username, String password) throws SQLException {
        // 1. 连接数据库
        Connection conn = DBUtils.getConnection();

        // 2. 得到查询对象
        Statement stmt = conn.createStatement();

        // 3. 执行sql语句
        String sql = "select * from user where username = '" + username + "' and password='" + password + "';";
        System.out.println(sql);
        ResultSet rs = stmt.executeQuery(sql);

        // 4. 得到结果集
        // 5. 返回结果
        if (rs.next()) {
            DBUtils.destoryResource(conn, stmt, rs, null);
            return true;
        } else {
            DBUtils.destoryResource(conn, stmt, rs, null);
            return false;
        }
    }
}
